package net.lab1024.sa.admin.module.business.goods.service;
import java.util.List;
import net.lab1024.sa.admin.module.business.goods.dao.OtherGroupDao;
import net.lab1024.sa.admin.module.business.goods.domain.form.OtherGroupQueryForm;
import net.lab1024.sa.admin.module.business.goods.domain.vo.OtherGroupVO;
import net.lab1024.sa.common.common.util.SmartPageUtil;
import net.lab1024.sa.common.common.domain.ResponseDTO;
import net.lab1024.sa.common.common.domain.PageResult;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 外部选品库 Service
 *
 * @Author jabari
 * @Date 2023-05-30 16:21:03
 * @Copyright 51dev.cn
 */

@Service
public class OtherGroupService {

    @Autowired
    private OtherGroupDao otherGroupDao;

    /**
     * 分页查询
     *
     * @param queryForm
     * @return
     */
    public PageResult<OtherGroupVO> queryPage(OtherGroupQueryForm queryForm) {
        Page<?> page = SmartPageUtil.convert2PageQuery(queryForm);
        List<OtherGroupVO> list = otherGroupDao.queryPage(page, queryForm);
        PageResult<OtherGroupVO> pageResult = SmartPageUtil.convert2PageResult(page, list);
        return pageResult;
    }


    /**
     * 批量删除
     *
     * @param idList
     * @return
     */
    public ResponseDTO<String> batchDelete(List<Integer> idList) {
        if (CollectionUtils.isEmpty(idList)){
            return ResponseDTO.ok();
        }

        otherGroupDao.deleteBatchIds(idList);
        return ResponseDTO.ok();
    }

    /**
     * 单个删除
     */
    public ResponseDTO<String> delete(Integer groupId) {
        if (null == groupId){
            return ResponseDTO.ok();
        }

        otherGroupDao.deleteById(groupId);
        return ResponseDTO.ok();
    }
}
